Public Class jfv

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        'If (TextBox1.Text = "" And TextBox2.Text = "" And TextBox3.Text = "" And TextBox4.Text = "" And TextBox5.Text = "" And TextBox6.Text = "" And TextBox7.Text = "" And TextBox8.Text = "" And TextBox9.Text = "" And TextBox10.Text = "" And TextBox11.Text = "" And TextBox12.Text = "" And TextBox13.Text = "" And TextBox14.Text = "" And TextBox15.Text = "" And TextBox16.Text = "" And TextBox17.Text = "" And TextBox18.Text = "" And TextBox19.Text = "" And TextBox20.Text = "" And TextBox21.Text = "" And TextBox22.Text = "" And TextBox23.Text = "" And TextBox24.Text = "") Then
        'MsgBox("Le programme exige au moins un jour férié...")
        'Exit Sub
        'End If
        If TextBox1.Text <> "" And TextBox2.Text <> "" Then
            If CDate(TextBox1.Text) > CDate(TextBox2.Text) Then
                MsgBox("Vous avez saisi des dates de départs après des dates d'arrivées, corrigez...")
                Exit Sub
            End If
        End If
        If (TextBox2.Text <> "" And TextBox1.Text = "") Then
            MsgBox("il y a des dates d'arrivées mais pas de départs, corrigez...")
            Exit Sub
        End If
        If TextBox3.Text <> "" And TextBox4.Text <> "" Then
            If CDate(TextBox3.Text) > CDate(TextBox4.Text) Then
                MsgBox("Vous avez saisi des dates de départs après des dates d'arrivées, corrigez...")
                Exit Sub
            End If
        End If
        If (TextBox4.Text <> "" And TextBox3.Text = "") Then
            MsgBox("il y a des dates d'arrivées mais pas de départs, corrigez...")
            Exit Sub
        End If
        If TextBox5.Text <> "" And TextBox6.Text <> "" Then
            If CDate(TextBox5.Text) > CDate(TextBox6.Text) Then
                MsgBox("Vous avez saisi des dates de départs après des dates d'arrivées, corrigez...")
                Exit Sub
            End If
        End If
        If (TextBox6.Text <> "" And TextBox5.Text = "") Then
            MsgBox("il y a des dates d'arrivées mais pas de départs, corrigez...")
            Exit Sub
        End If
        If TextBox7.Text <> "" And TextBox8.Text <> "" Then
            If CDate(TextBox7.Text) > CDate(TextBox8.Text) Then
                MsgBox("Vous avez saisi des dates de départs après des dates d'arrivées, corrigez...")
                Exit Sub
            End If
        End If
        If (TextBox8.Text <> "" And TextBox7.Text = "") Then
            MsgBox("il y a des dates d'arrivées mais pas de départs, corrigez...")
            Exit Sub
        End If
        If TextBox9.Text <> "" And TextBox10.Text <> "" Then
            If CDate(TextBox9.Text) > CDate(TextBox10.Text) Then
                MsgBox("Vous avez saisi des dates de départs après des dates d'arrivées, corrigez...")
                Exit Sub
            End If
        End If
        If (TextBox10.Text <> "" And TextBox9.Text = "") Then
            MsgBox("il y a des dates d'arrivées mais pas de départs, corrigez...")
            Exit Sub
        End If
        If TextBox11.Text <> "" And TextBox12.Text <> "" Then
            If CDate(TextBox11.Text) > CDate(TextBox12.Text) Then
                MsgBox("Vous avez saisi des dates de départs après des dates d'arrivées, corrigez...")
                Exit Sub
            End If
        End If
        If (TextBox12.Text <> "" And TextBox11.Text = "") Then
            MsgBox("il y a des dates d'arrivées mais pas de départs, corrigez...")
            Exit Sub
        End If
        If TextBox13.Text <> "" And TextBox14.Text <> "" Then
            If CDate(TextBox13.Text) > CDate(TextBox14.Text) Then
                MsgBox("Vous avez saisi des dates de départs après des dates d'arrivées, corrigez...")
                Exit Sub
            End If
        End If
        If (TextBox14.Text <> "" And TextBox13.Text = "") Then
            MsgBox("il y a des dates d'arrivées mais pas de départs, corrigez...")
            Exit Sub
        End If
        If TextBox15.Text <> "" And TextBox16.Text <> "" Then
            If CDate(TextBox15.Text) > CDate(TextBox16.Text) Then
                MsgBox("Vous avez saisi des dates de départs après des dates d'arrivées, corrigez...")
                Exit Sub
            End If
        End If
        If (TextBox16.Text <> "" And TextBox15.Text = "") Then
            MsgBox("il y a des dates d'arrivées mais pas de départs, corrigez...")
            Exit Sub
        End If
        If TextBox17.Text <> "" And TextBox18.Text <> "" Then
            If CDate(TextBox17.Text) > CDate(TextBox18.Text) Then
                MsgBox("Vous avez saisi des dates de départs après des dates d'arrivées, corrigez...")
                Exit Sub
            End If
        End If
        If (TextBox18.Text <> "" And TextBox17.Text = "") Then
            MsgBox("il y a des dates d'arrivées mais pas de départs, corrigez...")
            Exit Sub
        End If
        If TextBox19.Text <> "" And TextBox20.Text <> "" Then
            If CDate(TextBox19.Text) > CDate(TextBox20.Text) Then
                MsgBox("Vous avez saisi des dates de départs après des dates d'arrivées, corrigez...")
                Exit Sub
            End If
        End If
        If (TextBox20.Text <> "" And TextBox19.Text = "") Then
            MsgBox("il y a des dates d'arrivées mais pas de départs, corrigez...")
            Exit Sub
        End If
        If TextBox21.Text <> "" And TextBox22.Text <> "" Then
            If CDate(TextBox21.Text) > CDate(TextBox22.Text) Then
                MsgBox("Vous avez saisi des dates de départs après des dates d'arrivées, corrigez...")
                Exit Sub
            End If
        End If
        If (TextBox22.Text <> "" And TextBox21.Text = "") Then
            MsgBox("il y a des dates d'arrivées mais pas de départs, corrigez...")
            Exit Sub
        End If
        If TextBox23.Text <> "" And TextBox24.Text <> "" Then
            If CDate(TextBox23.Text) > CDate(TextBox24.Text) Then
                MsgBox("Vous avez saisi des dates de départs après des dates d'arrivées, corrigez...")
                Exit Sub
            End If
        End If
        If (TextBox24.Text <> "" And TextBox23.Text = "") Then
            MsgBox("il y a des dates d'arrivées mais pas de départs, corrigez...")
            Exit Sub
        End If
        Form1.ComboBox4.Items.Clear()

        Dim nomPersonne As String = ComboBox1.SelectedItem.ToString()
        If lireINI("jfv", nomPersonne & "_1") <> "" And lireINI("jfv", nomPersonne & "_2") <> "" Then
            Dim dt1 As Date = CDate(lireINI("jfv", nomPersonne & "_1"))
            Dim dt2 As Date = CDate(lireINI("jfv", nomPersonne & "_2"))
            Form1.ComboBox4.Items.Add(CStr(dt1)) ' pour éviter l'appel à la fonction dateadd avec 0 jour à ajouter => ainsi la boucle démarre à 1
            For i As Integer = 1 To CInt(DateDiff(DateInterval.Day, dt1, dt2))
                Form1.ComboBox4.Items.Add(CStr(DateAdd(DateInterval.Day, i, dt1)))
            Next
        ElseIf lireINI("jfv", nomPersonne & "_1") <> "" And lireINI("jfv", nomPersonne & "_2") = "" Then
            Form1.ComboBox4.Items.Add(lireINI("jfv", nomPersonne & "_1"))
        End If
        If lireINI("jfv", nomPersonne & "_3") <> "" And lireINI("jfv", nomPersonne & "_4") <> "" Then
            Dim dt1 As Date = CDate(lireINI("jfv", nomPersonne & "_3"))
            Dim dt2 As Date = CDate(lireINI("jfv", nomPersonne & "_4"))
            Form1.ComboBox4.Items.Add(CStr(dt1)) ' pour éviter l'appel à la fonction dateadd avec 0 jour à ajouter => ainsi la boucle démarre à 1
            For i As Integer = 1 To CInt(DateDiff(DateInterval.Day, dt1, dt2))
                Form1.ComboBox4.Items.Add(CStr(DateAdd(DateInterval.Day, i, dt1)))
            Next
        ElseIf lireINI("jfv", nomPersonne & "_3") <> "" And lireINI("jfv", nomPersonne & "_4") = "" Then
            Form1.ComboBox4.Items.Add(lireINI("jfv", nomPersonne & "_3"))
        End If
        If lireINI("jfv", nomPersonne & "_5") <> "" And lireINI("jfv", nomPersonne & "_6") <> "" Then
            Dim dt1 As Date = CDate(lireINI("jfv", nomPersonne & "_5"))
            Dim dt2 As Date = CDate(lireINI("jfv", nomPersonne & "_6"))
            Form1.ComboBox4.Items.Add(CStr(dt1)) ' pour éviter l'appel à la fonction dateadd avec 0 jour à ajouter => ainsi la boucle démarre à 1
            For i As Integer = 1 To CInt(DateDiff(DateInterval.Day, dt1, dt2))
                Form1.ComboBox4.Items.Add(CStr(DateAdd(DateInterval.Day, i, dt1)))
            Next
        ElseIf lireINI("jfv", nomPersonne & "_5") <> "" And lireINI("jfv", nomPersonne & "_6") = "" Then
            Form1.ComboBox4.Items.Add(lireINI("jfv", nomPersonne & "_5"))
        End If
        If lireINI("jfv", nomPersonne & "_7") <> "" And lireINI("jfv", nomPersonne & "_8") <> "" Then
            Dim dt1 As Date = CDate(lireINI("jfv", nomPersonne & "_7"))
            Dim dt2 As Date = CDate(lireINI("jfv", nomPersonne & "_8"))
            Form1.ComboBox4.Items.Add(CStr(dt1)) ' pour éviter l'appel à la fonction dateadd avec 0 jour à ajouter => ainsi la boucle démarre à 1
            For i As Integer = 1 To CInt(DateDiff(DateInterval.Day, dt1, dt2))
                Form1.ComboBox4.Items.Add(CStr(DateAdd(DateInterval.Day, i, dt1)))
            Next
        ElseIf lireINI("jfv", nomPersonne & "_7") <> "" And lireINI("jfv", nomPersonne & "_8") = "" Then
            Form1.ComboBox4.Items.Add(lireINI("jfv", nomPersonne & "_7"))
        End If
        If lireINI("jfv", nomPersonne & "_9") <> "" And lireINI("jfv", nomPersonne & "_10") <> "" Then
            Dim dt1 As Date = CDate(lireINI("jfv", nomPersonne & "_9"))
            Dim dt2 As Date = CDate(lireINI("jfv", nomPersonne & "_10"))
            Form1.ComboBox4.Items.Add(CStr(dt1)) ' pour éviter l'appel à la fonction dateadd avec 0 jour à ajouter => ainsi la boucle démarre à 1
            For i As Integer = 1 To CInt(DateDiff(DateInterval.Day, dt1, dt2))
                Form1.ComboBox4.Items.Add(CStr(DateAdd(DateInterval.Day, i, dt1)))
            Next
        ElseIf lireINI("jfv", nomPersonne & "_9") <> "" And lireINI("jfv", nomPersonne & "_10") = "" Then
            Form1.ComboBox4.Items.Add(lireINI("jfv", nomPersonne & "_9"))
        End If
        If lireINI("jfv", nomPersonne & "_11") <> "" And lireINI("jfv", nomPersonne & "_12") <> "" Then
            Dim dt1 As Date = CDate(lireINI("jfv", nomPersonne & "_11"))
            Dim dt2 As Date = CDate(lireINI("jfv", nomPersonne & "_12"))
            Form1.ComboBox4.Items.Add(CStr(dt1)) ' pour éviter l'appel à la fonction dateadd avec 0 jour à ajouter => ainsi la boucle démarre à 1
            For i As Integer = 1 To CInt(DateDiff(DateInterval.Day, dt1, dt2))
                Form1.ComboBox4.Items.Add(CStr(DateAdd(DateInterval.Day, i, dt1)))
            Next
        ElseIf lireINI("jfv", nomPersonne & "_11") <> "" And lireINI("jfv", nomPersonne & "_12") = "" Then
            Form1.ComboBox4.Items.Add(lireINI("jfv", nomPersonne & "_11"))
        End If
        If lireINI("jfv", nomPersonne & "_13") <> "" And lireINI("jfv", nomPersonne & "_14") <> "" Then
            Dim dt1 As Date = CDate(lireINI("jfv", nomPersonne & "_13"))
            Dim dt2 As Date = CDate(lireINI("jfv", nomPersonne & "_14"))
            Form1.ComboBox4.Items.Add(CStr(dt1)) ' pour éviter l'appel à la fonction dateadd avec 0 jour à ajouter => ainsi la boucle démarre à 1
            For i As Integer = 1 To CInt(DateDiff(DateInterval.Day, dt1, dt2))
                Form1.ComboBox4.Items.Add(CStr(DateAdd(DateInterval.Day, i, dt1)))
            Next
        ElseIf lireINI("jfv", nomPersonne & "_13") <> "" And lireINI("jfv", nomPersonne & "_14") = "" Then
            Form1.ComboBox4.Items.Add(lireINI("jfv", nomPersonne & "_13"))
        End If
        If lireINI("jfv", nomPersonne & "_15") <> "" And lireINI("jfv", nomPersonne & "_16") <> "" Then
            Dim dt1 As Date = CDate(lireINI("jfv", nomPersonne & "_15"))
            Dim dt2 As Date = CDate(lireINI("jfv", nomPersonne & "_16"))
            Form1.ComboBox4.Items.Add(CStr(dt1)) ' pour éviter l'appel à la fonction dateadd avec 0 jour à ajouter => ainsi la boucle démarre à 1
            For i As Integer = 1 To CInt(DateDiff(DateInterval.Day, dt1, dt2))
                Form1.ComboBox4.Items.Add(CStr(DateAdd(DateInterval.Day, i, dt1)))
            Next
        ElseIf lireINI("jfv", nomPersonne & "_15") <> "" And lireINI("jfv", nomPersonne & "_16") = "" Then
            Form1.ComboBox4.Items.Add(lireINI("jfv", nomPersonne & "_15"))
        End If
        If lireINI("jfv", nomPersonne & "_17") <> "" And lireINI("jfv", nomPersonne & "_18") <> "" Then
            Dim dt1 As Date = CDate(lireINI("jfv", nomPersonne & "_17"))
            Dim dt2 As Date = CDate(lireINI("jfv", nomPersonne & "_18"))
            Form1.ComboBox4.Items.Add(CStr(dt1)) ' pour éviter l'appel à la fonction dateadd avec 0 jour à ajouter => ainsi la boucle démarre à 1
            For i As Integer = 1 To CInt(DateDiff(DateInterval.Day, dt1, dt2))
                Form1.ComboBox4.Items.Add(CStr(DateAdd(DateInterval.Day, i, dt1)))
            Next
        ElseIf lireINI("jfv", nomPersonne & "_17") <> "" And lireINI("jfv", nomPersonne & "_18") = "" Then
            Form1.ComboBox4.Items.Add(lireINI("jfv", nomPersonne & "_17"))
        End If
        If lireINI("jfv", nomPersonne & "_19") <> "" And lireINI("jfv", nomPersonne & "_20") <> "" Then
            Dim dt1 As Date = CDate(lireINI("jfv", nomPersonne & "_19"))
            Dim dt2 As Date = CDate(lireINI("jfv", nomPersonne & "_20"))
            Form1.ComboBox4.Items.Add(CStr(dt1)) ' pour éviter l'appel à la fonction dateadd avec 0 jour à ajouter => ainsi la boucle démarre à 1
            For i As Integer = 1 To CInt(DateDiff(DateInterval.Day, dt1, dt2))
                Form1.ComboBox4.Items.Add(CStr(DateAdd(DateInterval.Day, i, dt1)))
            Next
        ElseIf lireINI("jfv", nomPersonne & "_19") <> "" And lireINI("jfv", nomPersonne & "_20") = "" Then
            Form1.ComboBox4.Items.Add(lireINI("jfv", nomPersonne & "_19"))
        End If
        If lireINI("jfv", nomPersonne & "_21") <> "" And lireINI("jfv", nomPersonne & "_22") <> "" Then
            Dim dt1 As Date = CDate(lireINI("jfv", nomPersonne & "_21"))
            Dim dt2 As Date = CDate(lireINI("jfv", nomPersonne & "_22"))
            Form1.ComboBox4.Items.Add(CStr(dt1)) ' pour éviter l'appel à la fonction dateadd avec 0 jour à ajouter => ainsi la boucle démarre à 1
            For i As Integer = 1 To CInt(DateDiff(DateInterval.Day, dt1, dt2))
                Form1.ComboBox4.Items.Add(CStr(DateAdd(DateInterval.Day, i, dt1)))
            Next
        ElseIf lireINI("jfv", nomPersonne & "_21") <> "" And lireINI("jfv", nomPersonne & "_22") = "" Then
            Form1.ComboBox4.Items.Add(lireINI("jfv", nomPersonne & "_21"))
        End If
        If lireINI("jfv", nomPersonne & "_23") <> "" And lireINI("jfv", nomPersonne & "_24") <> "" Then
            Dim dt1 As Date = CDate(lireINI("jfv", nomPersonne & "_23"))
            Dim dt2 As Date = CDate(lireINI("jfv", nomPersonne & "_24"))
            Form1.ComboBox4.Items.Add(CStr(dt1)) ' pour éviter l'appel à la fonction dateadd avec 0 jour à ajouter => ainsi la boucle démarre à 1
            For i As Integer = 1 To CInt(DateDiff(DateInterval.Day, dt1, dt2))
                Form1.ComboBox4.Items.Add(CStr(DateAdd(DateInterval.Day, i, dt1)))
            Next
        ElseIf lireINI("jfv", nomPersonne & "_23") <> "" And lireINI("jfv", nomPersonne & "_24") = "" Then
            Form1.ComboBox4.Items.Add(lireINI("jfv", nomPersonne & "_23"))
        End If
        Dim dates As New List(Of Date)
        For i = 0 To Form1.ComboBox4.Items.Count - 1
            dates.Add(Date.Parse(Form1.ComboBox4.Items(i)))
        Next
        Form1.ComboBox4.Items.Clear()
        dates.Sort()
        For i = 0 To dates.Count - 1
            Form1.ComboBox4.Items.Add(dates(i).ToShortDateString)
        Next
        If Form1.ComboBox4.Items.Count = 0 Then
            Form1.ComboBox4.Text = ""
        End If
        'Form1.ComboBox4.Sorted = True
        If Form1.ComboBox4.Items.Count > 0 Then
            Form1.ComboBox4.SelectedIndex = 0
        End If
        Me.Close()
    End Sub

    Private Sub jfv_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ' 1) On vide la combo au cas où
        ComboBox1.Items.Clear()

        ' 2) On copie tous les items depuis Form1.ComboBox2
        For Each perso As Object In Form1.ComboBox2.Items
            ComboBox1.Items.Add(perso)
        Next

        ' 3) On recherche l’index sélectionné dans Form1 et on l’applique
        If Form1.ComboBox2.SelectedIndex >= 0 Then
            ComboBox1.SelectedIndex = Form1.ComboBox2.SelectedIndex
        End If
        Dim nomPersonne As String = ComboBox1.SelectedItem.ToString()
        Dim j1, j2, j3, j4, j5, j6, j7, j8, j9, j10, j11, j12, j13, j14, j15, j16, j17, j18, j19, j20, j21, j22, j23, j24 As String
        j1 = lireINI("jfv", nomPersonne & "_1")
        TextBox1.Text = j1
        j2 = lireINI("jfv", nomPersonne & "_2")
        TextBox2.Text = j2
        j3 = lireINI("jfv", nomPersonne & "_3")
        TextBox3.Text = j3
        j4 = lireINI("jfv", nomPersonne & "_4")
        TextBox4.Text = j4
        j5 = lireINI("jfv", nomPersonne & "_5")
        TextBox5.Text = j5
        j6 = lireINI("jfv", nomPersonne & "_6")
        TextBox6.Text = j6
        j7 = lireINI("jfv", nomPersonne & "_7")
        TextBox7.Text = j7
        j8 = lireINI("jfv", nomPersonne & "_8")
        TextBox8.Text = j8
        j9 = lireINI("jfv", nomPersonne & "_9")
        TextBox9.Text = j9
        j10 = lireINI("jfv", nomPersonne & "_10")
        TextBox10.Text = j10
        j11 = lireINI("jfv", nomPersonne & "_11")
        TextBox11.Text = j11
        j12 = lireINI("jfv", nomPersonne & "_12")
        TextBox12.Text = j12
        j13 = lireINI("jfv", nomPersonne & "_13")
        TextBox13.Text = j13
        j14 = lireINI("jfv", nomPersonne & "_14")
        TextBox14.Text = j14
        j15 = lireINI("jfv", nomPersonne & "_15")
        TextBox15.Text = j15
        j16 = lireINI("jfv", nomPersonne & "_16")
        TextBox16.Text = j16
        j17 = lireINI("jfv", nomPersonne & "_17")
        TextBox17.Text = j17
        j18 = lireINI("jfv", nomPersonne & "_18")
        TextBox18.Text = j18
        j19 = lireINI("jfv", nomPersonne & "_19")
        TextBox19.Text = j19
        j20 = lireINI("jfv", nomPersonne & "_20")
        TextBox20.Text = j20
        j21 = lireINI("jfv", nomPersonne & "_21")
        TextBox21.Text = j21
        j22 = lireINI("jfv", nomPersonne & "_22")
        TextBox22.Text = j22
        j23 = lireINI("jfv", nomPersonne & "_23")
        TextBox23.Text = j23
        j24 = lireINI("jfv", nomPersonne & "_24")
        TextBox24.Text = j24

    End Sub
    Private Sub TextBox1_LostFocus(sender As Object, e As EventArgs) Handles TextBox1.LostFocus
        If (TextBox1.Text <> "" And TextBox1.Text.Length <> 10) Or (Not IsDate(TextBox1.Text) And TextBox1.Text <> "") Then
            MsgBox("Vous devez entrer la date sous ce format  " & DateTime.Now.Date)
            TextBox1.Text = ""
            TextBox1.Focus()
        End If
    End Sub
    Private Sub TextBox2_LostFocus(sender As Object, e As EventArgs) Handles TextBox2.LostFocus
        If (TextBox2.Text <> "" And TextBox2.Text.Length <> 10) Or (Not IsDate(TextBox2.Text) And TextBox2.Text <> "") Then
            MsgBox("Vous devez entrer la date sous ce format  " & DateTime.Now.Date)
            TextBox2.Text = ""
            TextBox2.Focus()
        End If
    End Sub
    Private Sub TextBox3_LostFocus(sender As Object, e As EventArgs) Handles TextBox3.LostFocus
        If (TextBox3.Text <> "" And TextBox3.Text.Length <> 10) Or (Not IsDate(TextBox3.Text) And TextBox3.Text <> "") Then
            MsgBox("Vous devez entrer la date sous ce format  " & DateTime.Now.Date)
            TextBox3.Text = ""
            TextBox3.Focus()
        End If
    End Sub
    Private Sub TextBox4_LostFocus(sender As Object, e As EventArgs) Handles TextBox4.LostFocus
        If (TextBox4.Text <> "" And TextBox4.Text.Length <> 10) Or (Not IsDate(TextBox4.Text) And TextBox4.Text <> "") Then
            MsgBox("Vous devez entrer la date sous ce format  " & DateTime.Now.Date)
            TextBox4.Text = ""
            TextBox4.Focus()
        End If
    End Sub
    Private Sub TextBox5_LostFocus(sender As Object, e As EventArgs) Handles TextBox5.LostFocus
        If (TextBox5.Text <> "" And TextBox5.Text.Length <> 10) Or (Not IsDate(TextBox5.Text) And TextBox5.Text <> "") Then
            MsgBox("Vous devez entrer la date sous ce format  " & DateTime.Now.Date)
            TextBox5.Text = ""
            TextBox5.Focus()
        End If
    End Sub
    Private Sub TextBox6_LostFocus(sender As Object, e As EventArgs) Handles TextBox6.LostFocus
        If (TextBox6.Text <> "" And TextBox6.Text.Length <> 10) Or (Not IsDate(TextBox6.Text) And TextBox6.Text <> "") Then
            MsgBox("Vous devez entrer la date sous ce format  " & DateTime.Now.Date)
            TextBox6.Text = ""
            TextBox6.Focus()
        End If
    End Sub
    Private Sub TextBox7_LostFocus(sender As Object, e As EventArgs) Handles TextBox7.LostFocus
        If (TextBox7.Text <> "" And TextBox7.Text.Length <> 10) Or (Not IsDate(TextBox7.Text) And TextBox7.Text <> "") Then
            MsgBox("Vous devez entrer la date sous ce format  " & DateTime.Now.Date)
            TextBox7.Text = ""
            TextBox7.Focus()
        End If
    End Sub
    Private Sub TextBox8_LostFocus(sender As Object, e As EventArgs) Handles TextBox8.LostFocus
        If (TextBox8.Text <> "" And TextBox8.Text.Length <> 10) Or (Not IsDate(TextBox8.Text) And TextBox8.Text <> "") Then
            MsgBox("Vous devez entrer la date sous ce format  " & DateTime.Now.Date)
            TextBox8.Text = ""
            TextBox8.Focus()
        End If
    End Sub
    Private Sub TextBox9_LostFocus(sender As Object, e As EventArgs) Handles TextBox9.LostFocus
        If (TextBox9.Text <> "" And TextBox9.Text.Length <> 10) Or (Not IsDate(TextBox9.Text) And TextBox9.Text <> "") Then
            MsgBox("Vous devez entrer la date sous ce format  " & DateTime.Now.Date)
            TextBox9.Text = ""
            TextBox9.Focus()
        End If
    End Sub
    Private Sub TextBox10_LostFocus(sender As Object, e As EventArgs) Handles TextBox10.LostFocus
        If (TextBox10.Text <> "" And TextBox10.Text.Length <> 10) Or (Not IsDate(TextBox10.Text) And TextBox10.Text <> "") Then
            MsgBox("Vous devez entrer la date sous ce format  " & DateTime.Now.Date)
            TextBox10.Text = ""
            TextBox10.Focus()
        End If
    End Sub
    Private Sub TextBox11_LostFocus(sender As Object, e As EventArgs) Handles TextBox11.LostFocus
        If (TextBox11.Text <> "" And TextBox11.Text.Length <> 10) Or (Not IsDate(TextBox11.Text) And TextBox11.Text <> "") Then
            MsgBox("Vous devez entrer la date sous ce format  " & DateTime.Now.Date)
            TextBox11.Text = ""
            TextBox11.Focus()
        End If
    End Sub
    Private Sub TextBox12_LostFocus(sender As Object, e As EventArgs) Handles TextBox12.LostFocus
        If (TextBox12.Text <> "" And TextBox12.Text.Length <> 10) Or (Not IsDate(TextBox12.Text) And TextBox12.Text <> "") Then
            MsgBox("Vous devez entrer la date sous ce format  " & DateTime.Now.Date)
            TextBox12.Text = ""
            TextBox12.Focus()
        End If
    End Sub
    Private Sub TextBox13_LostFocus(sender As Object, e As EventArgs) Handles TextBox13.LostFocus
        If (TextBox13.Text <> "" And TextBox13.Text.Length <> 10) Or (Not IsDate(TextBox13.Text) And TextBox13.Text <> "") Then
            MsgBox("Vous devez entrer la date sous ce format  " & DateTime.Now.Date)
            TextBox13.Text = ""
            TextBox13.Focus()
        End If
    End Sub
    Private Sub TextBox14_LostFocus(sender As Object, e As EventArgs) Handles TextBox14.LostFocus
        If (TextBox14.Text <> "" And TextBox14.Text.Length <> 10) Or (Not IsDate(TextBox14.Text) And TextBox14.Text <> "") Then
            MsgBox("Vous devez entrer la date sous ce format  " & DateTime.Now.Date)
            TextBox14.Text = ""
            TextBox14.Focus()
        End If
    End Sub
    Private Sub TextBox15_LostFocus(sender As Object, e As EventArgs) Handles TextBox15.LostFocus
        If (TextBox15.Text <> "" And TextBox15.Text.Length <> 10) Or (Not IsDate(TextBox15.Text) And TextBox15.Text <> "") Then
            MsgBox("Vous devez entrer la date sous ce format  " & DateTime.Now.Date)
            TextBox15.Text = ""
            TextBox15.Focus()
        End If
    End Sub
    Private Sub TextBox16_LostFocus(sender As Object, e As EventArgs) Handles TextBox16.LostFocus
        If (TextBox16.Text <> "" And TextBox16.Text.Length <> 10) Or (Not IsDate(TextBox16.Text) And TextBox16.Text <> "") Then
            MsgBox("Vous devez entrer la date sous ce format  " & DateTime.Now.Date)
            TextBox16.Text = ""
            TextBox16.Focus()
        End If
    End Sub
    Private Sub TextBox17_LostFocus(sender As Object, e As EventArgs) Handles TextBox17.LostFocus
        If (TextBox17.Text <> "" And TextBox17.Text.Length <> 10) Or (Not IsDate(TextBox17.Text) And TextBox17.Text <> "") Then
            MsgBox("Vous devez entrer la date sous ce format  " & DateTime.Now.Date)
            TextBox17.Text = ""
            TextBox17.Focus()
        End If
    End Sub
    Private Sub TextBox18_LostFocus(sender As Object, e As EventArgs) Handles TextBox18.LostFocus
        If (TextBox18.Text <> "" And TextBox18.Text.Length <> 10) Or (Not IsDate(TextBox18.Text) And TextBox18.Text <> "") Then
            MsgBox("Vous devez entrer la date sous ce format  " & DateTime.Now.Date)
            TextBox18.Text = ""
            TextBox18.Focus()
        End If
    End Sub
    Private Sub TextBox19_LostFocus(sender As Object, e As EventArgs) Handles TextBox19.LostFocus
        If (TextBox19.Text <> "" And TextBox19.Text.Length <> 10) Or (Not IsDate(TextBox19.Text) And TextBox19.Text <> "") Then
            MsgBox("Vous devez entrer la date sous ce format  " & DateTime.Now.Date)
            TextBox19.Text = ""
            TextBox19.Focus()
        End If
    End Sub
    Private Sub TextBox20_LostFocus(sender As Object, e As EventArgs) Handles TextBox20.LostFocus
        If (TextBox20.Text <> "" And TextBox20.Text.Length <> 10) Or (Not IsDate(TextBox20.Text) And TextBox20.Text <> "") Then
            MsgBox("Vous devez entrer la date sous ce format  " & DateTime.Now.Date)
            TextBox20.Text = ""
            TextBox20.Focus()
        End If
    End Sub
    Private Sub TextBox21_LostFocus(sender As Object, e As EventArgs) Handles TextBox21.LostFocus
        If (TextBox21.Text <> "" And TextBox21.Text.Length <> 10) Or (Not IsDate(TextBox21.Text) And TextBox21.Text <> "") Then
            MsgBox("Vous devez entrer la date sous ce format  " & DateTime.Now.Date)
            TextBox21.Text = ""
            TextBox21.Focus()
        End If
    End Sub
    Private Sub TextBox22_LostFocus(sender As Object, e As EventArgs) Handles TextBox22.LostFocus
        If (TextBox22.Text <> "" And TextBox22.Text.Length <> 10) Or (Not IsDate(TextBox22.Text) And TextBox22.Text <> "") Then
            MsgBox("Vous devez entrer la date sous ce format  " & DateTime.Now.Date)
            TextBox22.Text = ""
            TextBox22.Focus()
        End If
    End Sub
    Private Sub TextBox23_LostFocus(sender As Object, e As EventArgs) Handles TextBox23.LostFocus
        If (TextBox23.Text <> "" And TextBox23.Text.Length <> 10) Or (Not IsDate(TextBox23.Text) And TextBox23.Text <> "") Then
            MsgBox("Vous devez entrer la date sous ce format  " & DateTime.Now.Date)
            TextBox23.Text = ""
            TextBox23.Focus()
        End If
    End Sub
    Private Sub TextBox24_LostFocus(sender As Object, e As EventArgs) Handles TextBox24.LostFocus
        If (TextBox24.Text <> "" And TextBox24.Text.Length <> 10) Or (Not IsDate(TextBox24.Text) And TextBox24.Text <> "") Then
            MsgBox("Vous devez entrer la date sous ce format  " & DateTime.Now.Date)
            TextBox24.Text = ""
            TextBox24.Focus()
        End If
    End Sub

   
    
    Private Sub Button1_LostFocus(sender As Object, e As EventArgs) Handles Button1.LostFocus
        Form1.rafraichir()
    End Sub

    Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
        Dim nomPersonne As String = ComboBox1.SelectedItem.ToString()
        Dim nomHeure As String = "1" ' ou heure2, etc.
        Dim valeur As String = TextBox1.Text

        ecrireINI("jfv", nomPersonne & "_" & nomHeure, valeur)
    End Sub

    Private Sub Label2_Click(sender As Object, e As EventArgs) Handles Label2.Click

    End Sub

    Private Sub Label5_Click(sender As Object, e As EventArgs) Handles Label5.Click

    End Sub

    Private Sub Label7_Click(sender As Object, e As EventArgs) Handles Label7.Click

    End Sub

    Private Sub Label9_Click(sender As Object, e As EventArgs) Handles Label9.Click

    End Sub

    Private Sub Label11_Click(sender As Object, e As EventArgs) Handles Label11.Click

    End Sub

    Private Sub Label13_Click(sender As Object, e As EventArgs) Handles Label13.Click

    End Sub

    Private Sub Label15_Click(sender As Object, e As EventArgs) Handles Label15.Click

    End Sub

    Private Sub Label17_Click(sender As Object, e As EventArgs) Handles Label17.Click

    End Sub

    Private Sub Label19_Click(sender As Object, e As EventArgs) Handles Label19.Click

    End Sub

    Private Sub Label21_Click(sender As Object, e As EventArgs) Handles Label21.Click

    End Sub

    Private Sub Label23_Click(sender As Object, e As EventArgs) Handles Label23.Click

    End Sub

    Private Sub Label25_Click(sender As Object, e As EventArgs) Handles Label25.Click

    End Sub

    Private Sub TextBox23_TextChanged(sender As Object, e As EventArgs) Handles TextBox23.TextChanged
        Dim nomPersonne As String = ComboBox1.SelectedItem.ToString()
        Dim nomHeure As String = "23" ' ou heure2, etc.
        Dim valeur As String = TextBox23.Text

        ecrireINI("jfv", nomPersonne & "_" & nomHeure, valeur)
    End Sub

    Private Sub TextBox21_TextChanged(sender As Object, e As EventArgs) Handles TextBox21.TextChanged
        Dim nomPersonne As String = ComboBox1.SelectedItem.ToString()
        Dim nomHeure As String = "21" ' ou heure2, etc.
        Dim valeur As String = TextBox21.Text

        ecrireINI("jfv", nomPersonne & "_" & nomHeure, valeur)
    End Sub

    Private Sub TextBox19_TextChanged(sender As Object, e As EventArgs) Handles TextBox19.TextChanged
        Dim nomPersonne As String = ComboBox1.SelectedItem.ToString()
        Dim nomHeure As String = "19" ' ou heure2, etc.
        Dim valeur As String = TextBox19.Text

        ecrireINI("jfv", nomPersonne & "_" & nomHeure, valeur)
    End Sub

    Private Sub TextBox17_TextChanged(sender As Object, e As EventArgs) Handles TextBox17.TextChanged
        Dim nomPersonne As String = ComboBox1.SelectedItem.ToString()
        Dim nomHeure As String = "17" ' ou heure2, etc.
        Dim valeur As String = TextBox17.Text

        ecrireINI("jfv", nomPersonne & "_" & nomHeure, valeur)
    End Sub

    Private Sub TextBox15_TextChanged(sender As Object, e As EventArgs) Handles TextBox15.TextChanged
        Dim nomPersonne As String = ComboBox1.SelectedItem.ToString()
        Dim nomHeure As String = "15" ' ou heure2, etc.
        Dim valeur As String = TextBox15.Text

        ecrireINI("jfv", nomPersonne & "_" & nomHeure, valeur)
    End Sub

    Private Sub TextBox13_TextChanged(sender As Object, e As EventArgs) Handles TextBox13.TextChanged
        Dim nomPersonne As String = ComboBox1.SelectedItem.ToString()
        Dim nomHeure As String = "13" ' ou heure2, etc.
        Dim valeur As String = TextBox13.Text

        ecrireINI("jfv", nomPersonne & "_" & nomHeure, valeur)
    End Sub

    Private Sub TextBox11_TextChanged(sender As Object, e As EventArgs) Handles TextBox11.TextChanged
        Dim nomPersonne As String = ComboBox1.SelectedItem.ToString()
        Dim nomHeure As String = "11" ' ou heure2, etc.
        Dim valeur As String = TextBox11.Text

        ecrireINI("jfv", nomPersonne & "_" & nomHeure, valeur)
    End Sub

    Private Sub TextBox9_TextChanged(sender As Object, e As EventArgs) Handles TextBox9.TextChanged
        Dim nomPersonne As String = ComboBox1.SelectedItem.ToString()
        Dim nomHeure As String = "9" ' ou heure2, etc.
        Dim valeur As String = TextBox9.Text

        ecrireINI("jfv", nomPersonne & "_" & nomHeure, valeur)
    End Sub

    Private Sub TextBox7_TextChanged(sender As Object, e As EventArgs) Handles TextBox7.TextChanged
        Dim nomPersonne As String = ComboBox1.SelectedItem.ToString()
        Dim nomHeure As String = "7" ' ou heure2, etc.
        Dim valeur As String = TextBox7.Text

        ecrireINI("jfv", nomPersonne & "_" & nomHeure, valeur)
    End Sub

    Private Sub TextBox5_TextChanged(sender As Object, e As EventArgs) Handles TextBox5.TextChanged
        Dim nomPersonne As String = ComboBox1.SelectedItem.ToString()
        Dim nomHeure As String = "5" ' ou heure2, etc.
        Dim valeur As String = TextBox5.Text

        ecrireINI("jfv", nomPersonne & "_" & nomHeure, valeur)
    End Sub

    Private Sub TextBox3_TextChanged(sender As Object, e As EventArgs) Handles TextBox3.TextChanged
        Dim nomPersonne As String = ComboBox1.SelectedItem.ToString()
        Dim nomHeure As String = "3" ' ou heure2, etc.
        Dim valeur As String = TextBox3.Text

        ecrireINI("jfv", nomPersonne & "_" & nomHeure, valeur)
    End Sub

    Private Sub Label3_Click(sender As Object, e As EventArgs) Handles Label3.Click

    End Sub

    Private Sub Label4_Click(sender As Object, e As EventArgs) Handles Label4.Click

    End Sub

    Private Sub Label6_Click(sender As Object, e As EventArgs) Handles Label6.Click

    End Sub

    Private Sub TextBox6_TextChanged(sender As Object, e As EventArgs) Handles TextBox6.TextChanged
        Dim nomPersonne As String = ComboBox1.SelectedItem.ToString()
        Dim nomHeure As String = "6" ' ou heure2, etc.
        Dim valeur As String = TextBox6.Text

        ecrireINI("jfv", nomPersonne & "_" & nomHeure, valeur)
    End Sub

    Private Sub TextBox4_TextChanged(sender As Object, e As EventArgs) Handles TextBox4.TextChanged
        Dim nomPersonne As String = ComboBox1.SelectedItem.ToString()
        Dim nomHeure As String = "4" ' ou heure2, etc.
        Dim valeur As String = TextBox4.Text

        ecrireINI("jfv", nomPersonne & "_" & nomHeure, valeur)
    End Sub

    Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox2.TextChanged
        Dim nomPersonne As String = ComboBox1.SelectedItem.ToString()
        Dim nomHeure As String = "2" ' ou heure2, etc.
        Dim valeur As String = TextBox2.Text

        ecrireINI("jfv", nomPersonne & "_" & nomHeure, valeur)
    End Sub

    Private Sub Label8_Click(sender As Object, e As EventArgs) Handles Label8.Click

    End Sub

    Private Sub TextBox8_TextChanged(sender As Object, e As EventArgs) Handles TextBox8.TextChanged
        Dim nomPersonne As String = ComboBox1.SelectedItem.ToString()
        Dim nomHeure As String = "8" ' ou heure2, etc.
        Dim valeur As String = TextBox8.Text

        ecrireINI("jfv", nomPersonne & "_" & nomHeure, valeur)
    End Sub

    Private Sub TextBox10_TextChanged(sender As Object, e As EventArgs) Handles TextBox10.TextChanged
        Dim nomPersonne As String = ComboBox1.SelectedItem.ToString()
        Dim nomHeure As String = "10" ' ou heure2, etc.
        Dim valeur As String = TextBox10.Text

        ecrireINI("jfv", nomPersonne & "_" & nomHeure, valeur)
    End Sub

    Private Sub TextBox12_TextChanged(sender As Object, e As EventArgs) Handles TextBox12.TextChanged
        Dim nomPersonne As String = ComboBox1.SelectedItem.ToString()
        Dim nomHeure As String = "12" ' ou heure2, etc.
        Dim valeur As String = TextBox12.Text

        ecrireINI("jfv", nomPersonne & "_" & nomHeure, valeur)
    End Sub

    Private Sub TextBox14_TextChanged(sender As Object, e As EventArgs) Handles TextBox14.TextChanged
        Dim nomPersonne As String = ComboBox1.SelectedItem.ToString()
        Dim nomHeure As String = "14" ' ou heure2, etc.
        Dim valeur As String = TextBox14.Text

        ecrireINI("jfv", nomPersonne & "_" & nomHeure, valeur)
    End Sub

    Private Sub TextBox16_TextChanged(sender As Object, e As EventArgs) Handles TextBox16.TextChanged
        Dim nomPersonne As String = ComboBox1.SelectedItem.ToString()
        Dim nomHeure As String = "16" ' ou heure2, etc.
        Dim valeur As String = TextBox16.Text

        ecrireINI("jfv", nomPersonne & "_" & nomHeure, valeur)
    End Sub

    Private Sub TextBox18_TextChanged(sender As Object, e As EventArgs) Handles TextBox18.TextChanged
        Dim nomPersonne As String = ComboBox1.SelectedItem.ToString()
        Dim nomHeure As String = "18" ' ou heure2, etc.
        Dim valeur As String = TextBox18.Text

        ecrireINI("jfv", nomPersonne & "_" & nomHeure, valeur)
    End Sub

    Private Sub TextBox20_TextChanged(sender As Object, e As EventArgs) Handles TextBox20.TextChanged
        Dim nomPersonne As String = ComboBox1.SelectedItem.ToString()
        Dim nomHeure As String = "20" ' ou heure2, etc.
        Dim valeur As String = TextBox20.Text

        ecrireINI("jfv", nomPersonne & "_" & nomHeure, valeur)
    End Sub

    Private Sub TextBox22_TextChanged(sender As Object, e As EventArgs) Handles TextBox22.TextChanged
        Dim nomPersonne As String = ComboBox1.SelectedItem.ToString()
        Dim nomHeure As String = "22" ' ou heure2, etc.
        Dim valeur As String = TextBox22.Text

        ecrireINI("jfv", nomPersonne & "_" & nomHeure, valeur)
    End Sub

    Private Sub TextBox24_TextChanged(sender As Object, e As EventArgs) Handles TextBox24.TextChanged
        Dim nomPersonne As String = ComboBox1.SelectedItem.ToString()
        Dim nomHeure As String = "24" ' ou heure2, etc.
        Dim valeur As String = TextBox24.Text

        ecrireINI("jfv", nomPersonne & "_" & nomHeure, valeur)
    End Sub

    Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
        Dim nomPersonne As String = ComboBox1.SelectedItem.ToString()
        Dim j1, j2, j3, j4, j5, j6, j7, j8, j9, j10, j11, j12, j13, j14, j15, j16, j17, j18, j19, j20, j21, j22, j23, j24 As String
        j1 = lireINI("jfv", nomPersonne & "_1")
        TextBox1.Text = j1
        j2 = lireINI("jfv", nomPersonne & "_2")
        TextBox2.Text = j2
        j3 = lireINI("jfv", nomPersonne & "_3")
        TextBox3.Text = j3
        j4 = lireINI("jfv", nomPersonne & "_4")
        TextBox4.Text = j4
        j5 = lireINI("jfv", nomPersonne & "_5")
        TextBox5.Text = j5
        j6 = lireINI("jfv", nomPersonne & "_6")
        TextBox6.Text = j6
        j7 = lireINI("jfv", nomPersonne & "_7")
        TextBox7.Text = j7
        j8 = lireINI("jfv", nomPersonne & "_8")
        TextBox8.Text = j8
        j9 = lireINI("jfv", nomPersonne & "_9")
        TextBox9.Text = j9
        j10 = lireINI("jfv", nomPersonne & "_10")
        TextBox10.Text = j10
        j11 = lireINI("jfv", nomPersonne & "_11")
        TextBox11.Text = j11
        j12 = lireINI("jfv", nomPersonne & "_12")
        TextBox12.Text = j12
        j13 = lireINI("jfv", nomPersonne & "_13")
        TextBox13.Text = j13
        j14 = lireINI("jfv", nomPersonne & "_14")
        TextBox14.Text = j14
        j15 = lireINI("jfv", nomPersonne & "_15")
        TextBox15.Text = j15
        j16 = lireINI("jfv", nomPersonne & "_16")
        TextBox16.Text = j16
        j17 = lireINI("jfv", nomPersonne & "_17")
        TextBox17.Text = j17
        j18 = lireINI("jfv", nomPersonne & "_18")
        TextBox18.Text = j18
        j19 = lireINI("jfv", nomPersonne & "_19")
        TextBox19.Text = j19
        j20 = lireINI("jfv", nomPersonne & "_20")
        TextBox20.Text = j20
        j21 = lireINI("jfv", nomPersonne & "_21")
        TextBox21.Text = j21
        j22 = lireINI("jfv", nomPersonne & "_22")
        TextBox22.Text = j22
        j23 = lireINI("jfv", nomPersonne & "_23")
        TextBox23.Text = j23
        j24 = lireINI("jfv", nomPersonne & "_24")
        TextBox24.Text = j24
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Dim result As DialogResult = MessageBox.Show(
        "Voulez-vous vraiment poursuivre ?",       ' Le message
        "Confirmation",                            ' Le titre de la fenêtre
        MessageBoxButtons.OKCancel,               ' Les boutons OK et Annuler
        MessageBoxIcon.Question                   ' L’icône (optionnel)
    )

        ' Si l’utilisateur choisit OK...
        If result = DialogResult.OK Then
            If ComboBox1.Items.Count < 2 Then
                MessageBox.Show("Il faut au moins deux personnes dans ComboBox1.", "Attention",
                        MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                Return
            End If

            ' Fichier INI (chemin relatif ou absolu)
            Dim iniFile As String = ".\badgeuse.ini"

            ' 1) Première personne
            Dim firstPerson As String = ComboBox1.Items(0).ToString()

            ' 2) Lire les 24 clés de la section jfv
            Dim valeurs(23) As String
            For i As Integer = 1 To 24
                Dim fullKeySrc As String = $"{firstPerson}_{i}"
                valeurs(i - 1) = lireINI("jfv", fullKeySrc)
                Debug.WriteLine($"Lecture [jfv] {fullKeySrc} = '{valeurs(i - 1)}'")
            Next

            ' 3) Copier ces valeurs pour chaque autre personne
            For idx As Integer = 1 To ComboBox1.Items.Count - 1
                Dim pers As String = ComboBox1.Items(idx).ToString()
                For i As Integer = 1 To 24
                    Dim fullKeyDst As String = $"{pers}_{i}"
                    ecrireINI("jfv", fullKeyDst, valeurs(i - 1))
                    Debug.WriteLine($"Écriture [jfv] {fullKeyDst} ← '{valeurs(i - 1)}'")
                Next
            Next
            MessageBox.Show("Tous les jours fériés et vacances sont changés selon ceux de la première personne", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information)
            ' TODO : remplacez cette ligne par votre code métier

        End If
    End Sub
End Class